using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using DevExpress.XtraReports.UI;
using ViCode_LeVi.Controls.BTBData;
using ViCode_LeVi.Controls.Logs;
using ViCode_LeVi.Data;
using System.Globalization;

namespace ViCode_LeVi.Controls.Reports
{
    public partial class QQSTimeSeriesSubReport : DevExpress.XtraReports.UI.XtraReport
    {
        private XRTableCell cellID;
        private XRTableCell cellName;
        private XRTableCell cellQl1;
        private XRTableCell cellQl2;
        private XRTableCell cellQl3;
        private XRTableCell cellQlEnd1;
        private XRTableCell cellQlEnd2;
        private XRTableCell cellQlEnd3;
        private XRTableCell cellQlStart1;
        private XRTableCell cellQlStart2;
        private XRTableCell cellQlStart3;
        private XRTableCell cellQn1;
        private XRTableCell cellQn2;
        private XRTableCell cellQn3;
        private XRTableCell cellQnEnd1;
        private XRTableCell cellQnEnd2;
        private XRTableCell cellQnEnd3;
        private XRTableCell cellQnStart1;
        private XRTableCell cellQnStart2;
        private XRTableCell cellQnStart3;
        private XRTableCell cellSy1;
        private XRTableCell cellSy2;
        private XRTableCell cellSy3;
        private XRTableCell cellSyEnd1;
        private XRTableCell cellSyEnd2;
        private XRTableCell cellSyEnd3;
        private XRTableCell cellSyStart1;
        private XRTableCell cellSyStart2;
        private XRTableCell cellSyStart3;
        private DetailBand DetailQQSTimeSeriesSubReport;
        private GroupHeaderBand HeaderQQSTimeSeriesSubReport;
        private PeriodList m_aTimeLinePeriods;
        private XRTable xrTable1;
        private XRTable xrTable2;
        private XRTableCell xrTableCell1;
        private XRTableCell xrTableCell10;
        private XRTableCell xrTableCell13;
        private XRTableCell xrTableCell18;
        private XRTableCell xrTableCell2;
        private XRTableCell xrTableCell21;
        private XRTableCell xrTableCell3;
        private XRTableCell xrTableCell4;
        private XRTableCell xrTableCell5;
        private XRTableRow xrTableRow1;
        private XRTableRow xrTableRow2;
        private XRTableRow xrTableRow3;
        private XRTableRow xrTableRow6;

        public QQSTimeSeriesSubReport()
        {
            this.InitializeComponent();
        }

        private bool CreateDataBindings()
        {
            bool flag = true;
            try
            {
                this.cellID.DataBindings.Add("Text", base.DataSource, "ID");
                this.cellName.DataBindings.Add("Text", base.DataSource, "FactorName");
                this.cellQn1.DataBindings.Add("Text", base.DataSource, "Qn1");
                this.cellQn2.DataBindings.Add("Text", base.DataSource, "Qn2");
                this.cellQn3.DataBindings.Add("Text", base.DataSource, "Qn3");
                this.cellQl1.DataBindings.Add("Text", base.DataSource, "Ql1");
                this.cellQl2.DataBindings.Add("Text", base.DataSource, "Ql2");
                this.cellQl3.DataBindings.Add("Text", base.DataSource, "Ql3");
                this.cellSy1.DataBindings.Add("Text", base.DataSource, "Sy1");
                this.cellSy2.DataBindings.Add("Text", base.DataSource, "Sy2");
                this.cellSy3.DataBindings.Add("Text", base.DataSource, "Sy3");
            }
            catch (Exception exception)
            {
                flag = false;
                //rsErr = "Fehler in QQSTimeSeriesSubReport.CreateDataBindings: " + exception.Message;
                Log.LogException(exception);
            }
            return flag;
        }

        public bool CreateReport(ref bool bFactors)
        {
            bool flag = true;
            try
            {
                if (this.CreateTableHeader())
                {
                    var data = new ReportDataSourceHelper().GetReportQQSTimeSeriesList(this.TimeLinePeriods);
                    base.DataSource = data;
                    if (data != null && data.Length> 0)
                    {
                        bFactors = true;
                        return this.CreateDataBindings();
                    }
                    bFactors = false;
                    return flag;
                }
                flag = false;
            }
            catch (Exception exception)
            {
                flag = false;
                //rsErr = "Fehler in QQSTimeSeriesSubReport.CreateReport: " + exception.Message;
                Log.LogException(exception);
            }
            return flag;
        }

        private bool CreateTableHeader()
        {
            bool flag = true;
            PeriodList timeLinePeriods = this.TimeLinePeriods;
            try
            {
                if (timeLinePeriods != null)
                {
                    switch (timeLinePeriods.Count)
                    {
                        case 1:
                            this.cellQnStart1.Text = string.Empty;
                            this.cellQnStart2.Text = string.Empty;
                            this.cellQnStart3.Text = ((RootData) timeLinePeriods[0]).StartDate.ToString("MM/yyyy", CultureInfo.InvariantCulture) + "-";
                            this.cellQnEnd1.Text = string.Empty;
                            this.cellQnEnd2.Text = string.Empty;
                            this.cellQnEnd3.Text = ((RootData) timeLinePeriods[0]).EndDate.ToString("MM/yyyy", CultureInfo.InvariantCulture);
                            this.cellQlStart1.Text = string.Empty;
                            this.cellQlStart2.Text = string.Empty;
                            this.cellQlStart3.Text = ((RootData) timeLinePeriods[0]).StartDate.ToString("MM/yyyy", CultureInfo.InvariantCulture) + "-";
                            this.cellQlEnd1.Text = string.Empty;
                            this.cellQlEnd2.Text = string.Empty;
                            this.cellQlEnd3.Text = ((RootData) timeLinePeriods[0]).EndDate.ToString("MM/yyyy", CultureInfo.InvariantCulture);
                            this.cellSyStart1.Text = string.Empty;
                            this.cellSyStart2.Text = string.Empty;
                            this.cellSyStart3.Text = ((RootData) timeLinePeriods[0]).StartDate.ToString("MM/yyyy", CultureInfo.InvariantCulture) + "-";
                            this.cellSyEnd1.Text = string.Empty;
                            this.cellSyEnd2.Text = string.Empty;
                            this.cellSyEnd3.Text = ((RootData) timeLinePeriods[0]).EndDate.ToString("MM/yyyy", CultureInfo.InvariantCulture);
                            return flag;

                        case 2:
                            this.cellQnStart1.Text = string.Empty;
                            this.cellQnStart2.Text = ((RootData) timeLinePeriods[0]).StartDate.ToString("MM/yyyy", CultureInfo.InvariantCulture) + "-";
                            this.cellQnStart3.Text = ((RootData) timeLinePeriods[1]).StartDate.ToString("MM/yyyy", CultureInfo.InvariantCulture) + "-";
                            this.cellQnEnd1.Text = string.Empty;
                            this.cellQnEnd2.Text = ((RootData) timeLinePeriods[0]).EndDate.ToString("MM/yyyy", CultureInfo.InvariantCulture);
                            this.cellQnEnd3.Text = ((RootData) timeLinePeriods[1]).EndDate.ToString("MM/yyyy", CultureInfo.InvariantCulture);
                            this.cellQlStart1.Text = string.Empty;
                            this.cellQlStart2.Text = ((RootData) timeLinePeriods[0]).StartDate.ToString("MM/yyyy", CultureInfo.InvariantCulture) + "-";
                            this.cellQlStart3.Text = ((RootData) timeLinePeriods[1]).StartDate.ToString("MM/yyyy", CultureInfo.InvariantCulture) + "-";
                            this.cellQlEnd1.Text = string.Empty;
                            this.cellQlEnd2.Text = ((RootData) timeLinePeriods[0]).EndDate.ToString("MM/yyyy", CultureInfo.InvariantCulture);
                            this.cellQlEnd3.Text = ((RootData) timeLinePeriods[1]).EndDate.ToString("MM/yyyy", CultureInfo.InvariantCulture);
                            this.cellSyStart1.Text = string.Empty;
                            this.cellSyStart2.Text = ((RootData) timeLinePeriods[0]).StartDate.ToString("MM/yyyy", CultureInfo.InvariantCulture) + "-";
                            this.cellSyStart3.Text = ((RootData) timeLinePeriods[1]).StartDate.ToString("MM/yyyy", CultureInfo.InvariantCulture) + "-";
                            this.cellSyEnd1.Text = string.Empty;
                            this.cellSyEnd2.Text = ((RootData) timeLinePeriods[0]).EndDate.ToString("MM/yyyy", CultureInfo.InvariantCulture);
                            this.cellSyEnd3.Text = ((RootData) timeLinePeriods[1]).EndDate.ToString("MM/yyyy", CultureInfo.InvariantCulture);
                            return flag;

                        case 3:
                            this.cellQnStart1.Text = ((RootData) timeLinePeriods[0]).StartDate.ToString("MM/yyyy", CultureInfo.InvariantCulture) + "-";
                            this.cellQnStart2.Text = ((RootData) timeLinePeriods[1]).StartDate.ToString("MM/yyyy", CultureInfo.InvariantCulture) + "-";
                            this.cellQnStart3.Text = ((RootData) timeLinePeriods[2]).StartDate.ToString("MM/yyyy", CultureInfo.InvariantCulture) + "-";
                            this.cellQnEnd1.Text = ((RootData) timeLinePeriods[0]).EndDate.ToString("MM/yyyy", CultureInfo.InvariantCulture);
                            this.cellQnEnd2.Text = ((RootData) timeLinePeriods[1]).EndDate.ToString("MM/yyyy", CultureInfo.InvariantCulture);
                            this.cellQnEnd3.Text = ((RootData) timeLinePeriods[2]).EndDate.ToString("MM/yyyy", CultureInfo.InvariantCulture);
                            this.cellQlStart1.Text = ((RootData) timeLinePeriods[0]).StartDate.ToString("MM/yyyy", CultureInfo.InvariantCulture) + "-";
                            this.cellQlStart2.Text = ((RootData) timeLinePeriods[1]).StartDate.ToString("MM/yyyy", CultureInfo.InvariantCulture) + "-";
                            this.cellQlStart3.Text = ((RootData) timeLinePeriods[2]).StartDate.ToString("MM/yyyy", CultureInfo.InvariantCulture) + "-";
                            this.cellQlEnd1.Text = ((RootData) timeLinePeriods[0]).EndDate.ToString("MM/yyyy", CultureInfo.InvariantCulture);
                            this.cellQlEnd2.Text = ((RootData) timeLinePeriods[1]).EndDate.ToString("MM/yyyy", CultureInfo.InvariantCulture);
                            this.cellQlEnd3.Text = ((RootData) timeLinePeriods[2]).EndDate.ToString("MM/yyyy", CultureInfo.InvariantCulture);
                            this.cellSyStart1.Text = ((RootData) timeLinePeriods[0]).StartDate.ToString("MM/yyyy", CultureInfo.InvariantCulture) + "-";
                            this.cellSyStart2.Text = ((RootData) timeLinePeriods[1]).StartDate.ToString("MM/yyyy", CultureInfo.InvariantCulture) + "-";
                            this.cellSyStart3.Text = ((RootData) timeLinePeriods[2]).StartDate.ToString("MM/yyyy", CultureInfo.InvariantCulture) + "-";
                            this.cellSyEnd1.Text = ((RootData) timeLinePeriods[0]).EndDate.ToString("MM/yyyy", CultureInfo.InvariantCulture);
                            this.cellSyEnd2.Text = ((RootData) timeLinePeriods[1]).EndDate.ToString("MM/yyyy", CultureInfo.InvariantCulture);
                            this.cellSyEnd3.Text = ((RootData) timeLinePeriods[2]).EndDate.ToString("MM/yyyy", CultureInfo.InvariantCulture);
                            return flag;
                    }
                }
            }
            catch (Exception exception)
            {
                flag = false;
                //rsErr = "Fehler in QQSTimeSeriesSubReport.CreateTableHeader: " + exception.Message;
                Log.LogException(exception);
            }
            return flag;
        }
               

        public PeriodList TimeLinePeriods
        {
            get
            {
                return this.m_aTimeLinePeriods;
            }
            set
            {
                this.m_aTimeLinePeriods = value;
            }
        }
    }
    
}
